﻿/**
 * ...
 * @author kex
 */

package ;

import flash.display.Sprite;
import flash.ui.Keyboard;
import flash.events.Event;
import gui.hug.HUGButton;
import gui.hug.HUGEditField;
import gui.hug.HUGListBox;
import gui.hug.HUGPopupWindow;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;


class PopUpWindowManager {
	private var label 	: MyLabel;
	private var field 	: HUGEditField;
	private var button 	: HUGButton;
	private var list	: HUGListBox;
	private var pop		: HUGPopupWindow;
	private var window	: Sprite;
	private var index	: UInt;


	public function new(owner : Sprite,  list1 : HUGListBox, selectedIndex : UInt) {
		list = list1;
		window = owner;
		index = selectedIndex;
		pop = new HUGPopupWindow(	Std.int(list.x + HUGListBox.W), 									//x-coord
									Std.int(list.y + list.getSelectedIndex() * HUGListBox.ITEM_H),	//y-coord
									160,															//width
									130,															//height
									"WOW!!"															//title
								);
		window.addChild(pop);
		
		label = new MyLabel("You can change this!!");
		label.setLocation(20, 40);
		pop.addChild(label);
		
		field = new HUGEditField();
		field.setLocation(20, 62);
		field.setSize(120, 17);
		field.text = "new text";
		pop.addChild(field);

		button = new HUGButton("CHANGE");
		button.addEventListener(MouseEvent.CLICK, onClick);
		button.setLocation(20, 85);
		pop.addChild(button);
		
	}
	
	private function onClick(_) {
		list.replaceItemAt(index, field.getText());
		pop.visible = false;
	}
}